home *** CD-ROM | disk | FTP | other *** search
- /*
- CDRemainingTrack - An XFCN to report remaining time on disc
- ©Apple Computer, Inc. 1988
- All Rights Reserved.
-
- 88/11/08 BL°B First Version
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- C -q2 CDRemainingTrack.c
- link -sn Main=CDRemainingTrack -sn STDIO=CDRemainingTrack ∂
- -sn INTENV=CDRemainingTrack -rt XFCN=42 ∂
- -m CDRemainingTrack CDRemainingTrack.c.o "{CLibraries}"CRuntime.o ∂
- "{CLibraries}"StdCLib.o ∂
- -o HyperCommands
-
- This link directive puts the XCMD in the file "HyperCommands".
- Substitute the name of the stack you want it in. To move XCMDs
- between stacks, use ResEdit. They can be in an individual stack,
- the Home stack, the HyperCard application, or the System File.
-
- */
-
- #include <cd.h>
-
-
- /* **** WARNING: DO NOT USE GLOBAL VARIABLES! **** */
-
-
- /************************************************************************
- *
- * Function: CDRemainingTrack
- *
- * Purpose: return the remaining time on this disc.
- *
- * Returns: either 0, or an error
- * if it's a negative number, it's an error
- *
- * Side Effects:
- *
- * Description: We need no parameter:
- * Get the ioRefNum that we got from previously calling
- * CDOpen() by accessing the famous global
- * call the driver with a READQ call to find out
- * how absolute minute, second, block remaining.
- *
- ************************************************************************/
- pascal void
- CDRemainingTrack(paramPtr)
- XCmdBlockPtr paramPtr;
- {
- Str31 returnString;
- OSErr result;
- short ioRefNum;
- Handle refHandle;
- long Remaining[4]; /* minute, second, block */
- long currentMinute, currentSecond, currentBlock;
- long startMinute, startSecond, startBlock;
-
- /* Must be no parameter */
- if ((paramPtr->paramCount) != 0)
- {
- /* Report error in parameters by returning -1 */
- NumToStr(paramPtr, (long) -1, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- return;
- }
-
- /* Get the global ioRefNum and convert it. */
- refHandle = GetGlobal(paramPtr, GLOBALNAME);
- ioRefNum = atoi(*(refHandle));
- DisposHandle(refHandle);
- ioRefNum &= 0xFFFF; /* remove vRefNum; not needed. */
-
-
- result = ReadQ(ioRefNum, &Remaining[0], ¤tMinute, ¤tSecond, ¤tBlock);
-
- if (result == noErr)
- result = TrackStart(ioRefNum, Remaining[0]+1, &startMinute, &startSecond, &startBlock);
-
- if (result != noErr) /* we specified an invalid track. Use disc time */
- result = DiscTime(ioRefNum, &startMinute, &startSecond, &startBlock);
-
- if (result == noErr)
- {
- TimeDiff(&Remaining[1], &Remaining[2], &Remaining[3],
- startMinute, startSecond, startBlock,
- currentMinute, currentSecond, currentBlock);
- }
-
- if (result == noErr)
- {
- /* convert each value to a string, concatenate, & return. */
- FormatString(&returnString, Remaining, 4);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- }
- else
- {
- /* We got an error. Convert result to string & return it as error */
- NumToStr(paramPtr, (long) result, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- }
- }
-
- /* C routines for HyperCard callbacks */
- #include <XCmdGlue.inc.c>
-